<?php
	class SuKienDAO
	{
		public static function PartseToDanhSachSuKien($row)
		{
			$skDTO=new SuKienDTO();
			$skDTO->sk_ma= $row["sk_ma"];
			$skDTO->sk_ten= $row["sk_ten"];
			$skDTO->sk_ngay_bat_dau= $row["sk_ngay_bat_dau"];
			$skDTO->sk_ngay_ket_thuc= $row["sk_ngay_ket_thuc"];
			$skDTO->sk_mo_ta= $row["sk_mo_ta"];
			$skDTO->sk_ma_gian_hang= $row["sk_ma_gian_hang"];
			$skDTO->sk_so_luong_thich= SuKienDAO::DemSoNguoiThichSuKien($skDTO->sk_ma);
			return $skDTO;
		}
		public static function DemSoSuKienTheoMaGH($magh)
		{
			$sql="Select count(*)as soluong From su_kien Where sk_ma_gian_hang='$magh'";
			$result = QuerySQL($sql);
			$skDTO=null;
			while($row = mysql_fetch_array($result))
			{
				$skDTO = $row["soluong"];
			}
			StopConnection();
			return $skDTO;
		}
		public static function LayThongTinSuKien($mask)
		{
			$sql="Select * From su_kien Where sk_ma='$mask'";
			$result = QuerySQL($sql);
			$skDTO=null;
			while($row = mysql_fetch_array($result))
			{
				$skDTO = SuKienDAO::PartseToDanhSachSuKien($row);
			}
			StopConnection();
			return $skDTO;
		}
		public static function LayDanhSachSuKienTheoMaGH($magh,$start,$end)
		{
			$sql="Select * From su_kien Where sk_ma_gian_hang='$magh' order by 	sk_ngay_bat_dau DESC Limit $start,$end";
			$result = QuerySQL($sql);
			$skDTO=null;
			$i=0;
			while($row = mysql_fetch_array($result))
			{
				$skDTO[$i] = SuKienDAO::PartseToDanhSachSuKien($row);
				$i=$i+1;
			}
			StopConnection();
			return $skDTO;
		}
		public static function DemSoNguoiThichSuKien($mask)
		{
			$sql="Select count(*) as soluong From thich_su_kien Where tsk_ma_su_kien='$mask'";
			$result = QuerySQL($sql);
			$ghDTO=null;
			while($row = mysql_fetch_array($result))
			{
				$ghDTO = $row["soluong"];
			}
			//StopConnection();
			return $ghDTO;
		}
		public static function KiemTraThichSuKien($mask,$username)
		{
			$sql="Select count(*) as soluong From thich_su_kien Where tsk_ma_su_kien='$mask' and tsk_username='$username'";
			$result = QuerySQL($sql);
			$ghDTO=null;
			while($row = mysql_fetch_array($result))
			{
				$ghDTO = $row["soluong"];
			}
			StopConnection();
			return $ghDTO;
		}
		public static function DemSoLuongBinhLuan($mask)
		{
			$sql="Select count(*) as soluong From binh_luan_su_kien Where blsk_ma_su_kien='$mask'";
			$result = QuerySQL($sql);
			$ghDTO=null;
			while($row = mysql_fetch_array($result))
			{
				$ghDTO = $row["soluong"];
			}
			StopConnection();
			return $ghDTO;
		}
		public static function ThemThichSuKien($username,$mask)
		{
			$sql="Insert into thich_su_kien(tsk_username,tsk_ma_su_kien) values('$username','$mask')";
			 $result = QuerySQL($sql);
			 StopConnection();
			return $result;
		}
		public static function XoaThichSuKien($username,$mask)
		{
			$sql="Delete From thich_su_kien where tsk_username='$username' and tsk_ma_su_kien='$mask'";
			 $result = QuerySQL($sql);
			 StopConnection();
			return $result;
		}
	}
?>